/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { addMinGanCi } from '@/services/yz/sensitive';
import { ModalForm, ProFormTextArea } from '@ant-design/pro-form';
import { Button, message } from 'antd';
import React from 'react';

const SensitiveWordModal: React.FC<{ activeKey: string; reload: () => void }> = (props) => {
  const { activeKey, reload } = props;

  const label = {
    '1': '驿站名称',
    '2': '驿站地址',
    '3': '取件码',
  };
  const title = `${label[activeKey]}关键词`;

  return (
    <ModalForm
      title={`添加${title}`}
      trigger={
        <Button style={{ marginLeft: 20 }} type='primary'>
          {title}
        </Button>
      }
      width={400}
      modalProps={{
        destroyOnClose: true,
        footer: null,
        centered: true,
      }}
      onFinish={async ({ word }: { word: string }) => {
        if (!word) {
          message.error('请输入关键词');
          return false;
        }
        const { code } = await addMinGanCi({ word, type: activeKey });
        if (code == 0) {
          message.info('添加成功');
          reload();
        }
        return code == 0;
      }}
    >
      <ProFormTextArea name='word' placeholder={'请输入关键词'} />
    </ModalForm>
  );
};

export default SensitiveWordModal;
